package com.qiwx.pigeon.presenter;


import com.qiwx.pigeon.base.BasePresenter;
import com.qiwx.pigeon.base.IBaseView;
import com.qiwx.pigeon.data.network.ApiManager;
import com.qiwx.pigeon.data.network.BaseListResponse;
import com.qiwx.pigeon.data.network.BaseResponse;
import com.qiwx.pigeon.data.network.ResponseSubscriber;
import com.qiwx.pigeon.data.params.QueryWareHouseParam;
import com.qiwx.pigeon.data.vo.WareHouseBean;
import com.qiwx.pigeon.viewinterface.IWareHouseView;

import java.lang.ref.WeakReference;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;


/**
 * @description
 * @Author qiwx
 * @Date 2020-04-16 11:30
 * 鸽仓管理
 **/
public class WareHousePresenter extends BasePresenter<IWareHouseView> {

    public WareHousePresenter(WeakReference<IWareHouseView> from) {
        super(from);
    }

    //获取鸽仓
    public void getHouses(QueryWareHouseParam params) {
        ApiManager.getApiServer().getHouses(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseListResponse<WareHouseBean>>(true) {
            @Override
            public IBaseView getIView() {
                return getView();
            }

            @Override
            public void onSuccess(BaseListResponse<WareHouseBean> response) {
                getView().onQuerySuccess(response.data);
            }

        });
    }
    //添加鸽仓
    public void addHouse(QueryWareHouseParam params) {
        ApiManager.getApiServer().addHouse(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse<WareHouseBean>>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse<WareHouseBean> response) {
                        getView().onAddSuccess(response.data);

                    }

                });
    }
    //删除鸽仓 status 1 只删除鸽笼 0 鸽仓一起删除
    public void deleteHouse(QueryWareHouseParam params) {
        ApiManager.getApiServer().deleteHouse(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse<WareHouseBean>>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse<WareHouseBean> response) {
                        getView().onDeleteSuccess(response.data);

                    }

                });
    }


}
